//version:1.0.0
window.save = function () {
    let data = window.vueInstance.$children[0].$children[0].$children[0].$children[1].$children[1].$children[0];
    if (!data.$route.query.ticket && !data.$route.query.projid) return;
    data.formValidate([formNames]);
    data.customBackFun();
};
export default {
    data() {
        return {
            activeName2: '1',
            tableData1: {},
            demo: ['序号','年度','账目分类','缴费基数','记账月数','账户累计','个人累计','单位划账','个人缴费','社平划账','单位划账利息','个人划账利息','社平划账利息','缴费备注'],
            tableData2: {},
            fil: ['序号','账目类型','费款所属期','对应费款所属期','到账年月','缴费基数','缴费月数','单位划入','个人缴费','社平划入','应收类型','应收类型明细','个人账目状态','首次个人账目状态明细','个人账目状态明细'],

            rules:{

            },
            codeTypes:{

            },
            codeTypeFilters:{

            },
            pager: {
                page: 1,
                size: 10
            },
            total: 0,
        }
    },
    computed: {
        refresh() {
            return localStorage.getItem('refresh') || false;
        },
        functionId() {
            if (this.$store.getters.init.path !== this.$route.path) return;
            if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
            if (this.$store.getters.init.mdParam.functionid === undefined) return;
            return this.$store.getters.init.mdParam.functionid;
        },
        backFun() {
            return this.$store.getters.backFun;
        },
        init_tableData1() {
            return this.$store.getters.init.tableData1;
        },
        doInittableData1: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData1;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData2() {
            return this.$store.getters.init.tableData2;
        },
        doInittableData2: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData2;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },

    },
    created() {
        let param = {
            path: this.$route.path,
            codeTypes:this.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            tableData1:this.tableData1,
            tableData2:this.tableData2

        };
        if (this.refresh === 'true') {
            this.$store.dispatch('SET_INIT', param);
            sessionStorage.removeItem(this.$route.path);
        }
        if (this.$route.query.keepAlive === undefined) {
            this.$store.dispatch('SET_INIT', param);
        }
    },
    watch: {
        refresh: {
            handler(value) {
                return value;
            },
        deep: true
        },
        doInittableData1: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData1(value);
            },
            deep: true
        },
        doInittableData2: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData2(value);
            },
            deep: true
        },

        backFun: {
            handler(value) {
                if (value === null) return;
                this.customBackFun();
                let backFun = [];
                backFun = value.split(',');
                if (backFun.indexOf('rDoInit') >= 0) {
            let codeTypes = {

            };
            let tableData1= {};
            let tableData2= {};

        let param = {
            path: this.$route.path,
            codeTypes:codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            tableData1:tableData1,
            tableData2:tableData2

        };
                    this.$store.dispatch('SET_INIT', param);
                }
            }
        }
    },
    mounted() {
        if (this.$store.getters.cacheData === null) return;
        if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
        if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
        if (this.$store.getters.cacheData[this.$route.path].tableData1 !== undefined) {
            this.gettableData1(this.$store.getters.cacheData[this.$route.path].tableData1);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData2 !== undefined) {
            this.gettableData2(this.$store.getters.cacheData[this.$route.path].tableData2);
        }

    },
    beforeRouteLeave(to, from, next) {
        let param = {
            path: this.$route.path,
            codeTypes: this.$store.getters.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            tableData1:this.tableData1,
            tableData2:this.tableData2

        };
        if (from) {
            this.$store.dispatch('SET_CACHEDATA', param);
        }
        next();
    },
    methods: {
        gettableData1(value) {
            this.tableData1 = value;
        },
        gettableData2(value) {
            this.tableData2 = value;
        },


        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        handleEdit(id) {
            this.dialogFormVisible = true;
        },
        deleteCurrentRow(val){
            this.tableData.Data.splice(this.tableData.Data.findIndex((value,index,ary) => value == val),1);
        },

        customBackFun(){//自定义方法体
},
    },
}
